*************************************************************************
*																		*
*			Campaign Panel Book Do-File Chapter 2 -						* 
*			Graph: Selective Involvement (Campaigncontact)				*
*																		*
*************************************************************************	

*gen lfdn = _n
list lfdn in 1/20


* get overview over variables
fre ?_indiff?
sum ?_indiff* // all waves

tab a_indiff1 a_w1, m						//Add W2-starters 
gen a_new_indiff1 = a_indiff1 if a_w1==1
replace a_new_indiff1 = a_indiff2 if a_w1==0
tab a_new_indiff1 a_w1, m
tab a_new_indiff1 a_indiff1, m

gen b_new_indiff1 = b_indiff1
tab b_new_indiff1 b_indiff1, m

gen a_newpolint1 = a_polint2
gen b_newpolint1 = b_polint1

fre ?_pidyes?
sum ?_pidyes? //Waves 1, 3, 5, 7



tab a_pidyes1 a_w1, m		//W2-starters already included


fre ?_polint?
sum ?_polint?	//in a: waves 2, 4, 6, 7
				//in b: waves 1, 2, 3, 4, 5, 6, 7

sum ?_countcontact?		//waves 2-7 (relevant: 2-6)




foreach year in a b {
gen `year'_mysample = 1 if !missing(`year'_countcontact2, `year'_countcontact3, `year'_countcontact4, ///
	`year'_countcontact5, `year'_countcontact6)
}

fre ?_mysample

save "${data}\data2009_2013 participants 7 waves.dta", replace

	
reshape long a_countcontact b_countcontact, i(lfdn) j(welle)

fre ?_indiff?

sum a_countcontact if welle == 2
fre a_countcontact if welle == 2


* create variable to save coefficients of reg-output
foreach year in a b {
gen `year'_coeffpolint = .
gen `year'_coeffpidyes = .
gen `year'_coeffindiff = .
}

reg a_countcontact a_polint2 a_pidyes1 a_indiff1 ///
	if a_mysample==1 & welle==2

ereturn list, all	


fre a_weight


* regress constant IV on changing DV and save it in coefficient-variables
foreach year in a b {
foreach num of numlist 2/6 {
reg `year'_countcontact `year'_newpolint1 `year'_pidyes1 ///
	`year'_new_indiff1 ///
	if `year'_mysample==1 & welle==`num' [pw=`year'_weight]
replace `year'_coeffpolint = _b[`year'_newpolint1] if welle==`num' & `year'_mysample==1	
replace `year'_coeffpidyes = _b[`year'_pidyes1] if welle==`num' & `year'_mysample==1	
replace `year'_coeffindiff = _b[`year'_new_indiff1] if welle==`num' & `year'_mysample==1	
}
}

sum a_coeffpolint
tab a_coeffpolint welle



* graphs for coefficients (b/w)

graph set window fontface "Times New Roman"

sort welle	//necessary so that stata does not connect all dots with each other

fre welle
gen welle2 = welle if welle != 7
fre welle2

graph twoway ///
	(connected a_coeffpolint welle2 /*, lcolor(gs0) lpattern(dot) msymbol(T) mcolor(gs0)*/) ///
	(connected a_coeffpidyes welle2 /*, lcolor(gs6) lpattern(dash) msymbol(D) mcolor(gs6)*/) ///
	(connected a_coeffindiff welle2 /*, lcolor(gs10) lpattern(solid) msymbol(O) mcolor(gs10)*/), ///
		title("2009", size(medsmall)) ///
		legend(label(1 "Political interest") label(2 "Party identification") ///
		label(3 "Indifference") cols(3) region(lwidth(none)) size(small)) ///
		xtitle(" ", alignment(bottom) margin(medium)) xlabel(2(1)6) ///
		ytitle("OLS-coefficient", margin(medium)) ylabel(,angle(horizontal))  ///
		scheme(s1mono) name(coeff09, replace)
		
graph twoway ///
	(connected b_coeffpolint welle2 /*, lcolor(gs0) lpattern(dot) msymbol(T) mcolor(gs0)*/) ///
	(connected b_coeffpidyes welle2 /*, lcolor(gs6) lpattern(dash) msymbol(D) mcolor(gs6)*/) ///
	(connected b_coeffindiff welle2 /*, lcolor(gs10) lpattern(solid) msymbol(O) mcolor(gs10)*/), ///
		title("2013", size(medsmall)) ///
		legend(label(1 "Political interest") label(2 "Party identification") ///
		label(3 "Indifference") cols(3) region(lwidth(none)) size(small)) ///
		xtitle("Wave", alignment(bottom) margin(medium)) ///
		xscale(range(2 6)) xlabel(2(1)6) ///
		ytitle("OLS-coefficient", margin(medium)) ylabel(,angle(horizontal))  ///
		scheme(s1mono) name(coeff13, replace)

* normal speichern	
grc1leg coeff09 coeff13, ///
	scheme(s1mono) iscale(.75) imargin(30 30 0 0) rows(2) ycommon note("", margin(medium) ///
	position(6) ) title("Selective Involvement") 
graph export "${path}\Reproducible Do-Files\Chapter 2\Figures\selective_involvement_coeffplot.png", width(2000) ///
	height(1000) replace	
	

	* wmf-format
grc1leg coeff09 coeff13, ///
	scheme(s1mono) iscale(.75) imargin(30 30 0 0) rows(2) ycommon note("", margin(medium) position(6)) title("Selective Involvement") 
graph export "${path}\Reproducible Do-Files\Chapter 2\Figures/selective_involvement_coeffplot.wmf", replace


*ohne titel speichern
graph set window fontface "Times New Roman"

grc1leg coeff09 coeff13, ///
	row(2) iscale(.75) imargin(30 30 0 0) scheme(s1mono) ycommon ///
	 position(6)
graph export "${path}\Reproducible Do-Files\Chapter 2\Figures/selective_involvement_coeffplot_notitle.tif", ///
	width(2500) ///
	height(2250) replace	
	

	* wmf-format
grc1leg coeff09 coeff13, ///
	row(2) iscale(.75) imargin(30 30 0 0) scheme(s1mono) ycommon ///
	 position(6)
graph export "${path}\Reproducible Do-Files\Chapter 2\Figures/selective_involvement_coeffplot_notitle.wmf", replace




